#include "startupdialog.h"
#include "ui_startupdialog.h"
#include "lanqwindow.h"
#include "../QCommon/user.h"
#include "../QClient/QClientInterface.h"
#include "uicontrol.h"
#include <QMessageBox>

StartupDialog::StartupDialog(QWidget *parent)
    : QDialog(parent), ui(new Ui::StartupDialog)
{
    ui->setupUi(this);
    this->setWindowTitle(QString("Welcome!"));
    this->setWindowIcon(QIcon("./ico/logo16.png"));
    connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(okClicked()));
    connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(close()));
}

StartupDialog::~StartupDialog()
{
    delete ui;
}

void StartupDialog::okClicked()
{
    QString q_name = ui->nameEdit->text();
    if(q_name == ""){
        QMessageBox::warning(NULL, "Warning", "The nick name should not be empty!","OK");
        return;
    }

    // my informations
    string name = q_name.toStdString();
    Gender gender;
    Status status;

    // Get gender
    if(ui->femaleRadio->isChecked()){
        gender = female;
    }else if(ui->maleRadio->isChecked()){
        gender = male;
    }else{
        QMessageBox::warning( this, "Warning","Please select your gender.","OK");
        return;
    }

    // Get status
    if(ui->comboBox->currentIndex()==0)
        status = online;
    else
        status = stealth;

    User* user = new User;
    user->gender = gender;
    user->name = name;
    user->status = status;
    User u = *user;
    setUser(*user);
    //UIControl::getInstance().show_lanq_window(u);
    LanqWindow *win = new LanqWindow(u);
    win->show();
    UIControl::set_lanq_window(win);
    QDialog::accept();
}
